namespace PhoneBook.Data.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class init : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Contact",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Hello = c.String(),
                        UserName = c.String(maxLength: 1000),
                        Memo = c.String(maxLength: 1000),
                        ParentContact_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Contact", t => t.ParentContact_Id)
                .Index(t => t.ParentContact_Id);
            
            CreateTable(
                "dbo.Phones",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        PhoneType = c.Int(nullable: false),
                        PhoneNumber = c.String(maxLength: 30),
                        Contact_Id = c.Int(),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.Contact", t => t.Contact_Id)
                .Index(t => t.Contact_Id);
            
            CreateTable(
                "dbo.UserGroup",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        GroupName = c.String(maxLength: 1000),
                    })
                .PrimaryKey(t => t.Id);
            
            CreateTable(
                "dbo.UserGroupContacts",
                c => new
                    {
                        UserGroup_Id = c.Int(nullable: false),
                        Contact_Id = c.Int(nullable: false),
                    })
                .PrimaryKey(t => new { t.UserGroup_Id, t.Contact_Id })
                .ForeignKey("dbo.UserGroup", t => t.UserGroup_Id, cascadeDelete: true)
                .ForeignKey("dbo.Contact", t => t.Contact_Id, cascadeDelete: true)
                .Index(t => t.UserGroup_Id)
                .Index(t => t.Contact_Id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.UserGroupContacts", "Contact_Id", "dbo.Contact");
            DropForeignKey("dbo.UserGroupContacts", "UserGroup_Id", "dbo.UserGroup");
            DropForeignKey("dbo.Phones", "Contact_Id", "dbo.Contact");
            DropForeignKey("dbo.Contact", "ParentContact_Id", "dbo.Contact");
            DropIndex("dbo.UserGroupContacts", new[] { "Contact_Id" });
            DropIndex("dbo.UserGroupContacts", new[] { "UserGroup_Id" });
            DropIndex("dbo.Phones", new[] { "Contact_Id" });
            DropIndex("dbo.Contact", new[] { "ParentContact_Id" });
            DropTable("dbo.UserGroupContacts");
            DropTable("dbo.UserGroup");
            DropTable("dbo.Phones");
            DropTable("dbo.Contact");
        }
    }
}
